package pcsd.test;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import pcsd.server.JobQueueServer;
import pcsd.task.Fib;

/**
 * This class starts the server and gives it Fibonacci number 
 * calculation tasks.
 *
 * @author Benjamin Ertl, Justinas Murzinas, Boyan Mihaylov
 */
public class FibTestJob {

    /**
     * Program entry point.
     * 
     * @param args The command-line arguments.
     */
	public static void main(String[] args) {
		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new SecurityManager());
		}
		try {
			// Find the server
			String name = "server";
			Registry registry = LocateRegistry.getRegistry();
			JobQueueServer serv = (JobQueueServer) registry.lookup(name);

			/**
			 * Start enqueuing tasks.
			 */
			for(int i = 0; i < 100; i++) {
				System.out.print("Enqueuing " + i);
				serv.enqueueTask(new Fib(i % 50));
				System.out.println(" done");
			}
			System.out.println("Done enqueuing task.");
		} 
		catch (Exception e) {
			System.err.println("Test exception:");
			e.printStackTrace();
		}
	}
}
